{
  LX ToolUI module

  Based on modo's SDK lxtoolui.h which is:

  Copyright (c) 2008-2012 Luxology LLC

  Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the "Software"),
  to deal in the Software without restriction, including without limitation
  the rights to use, copy, modify, merge, publish, distribute, sublicense,
  and/or sell copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.   Except as contained
  in this notice, the name(s) of the above copyright holders shall not be
  used in advertising or otherwise to promote the sale, use or other dealings
  in this Software without prior written authorization.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  DEALINGS IN THE SOFTWARE.
}

{
  Copyright (c) 2012, David Ballesteros and Jameel Halabi

  This unit is part of the BLAISEmodo wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit Lx_ToolUI;

{$mode objfpc}{$H+}

interface

uses
  Lx_Result, Lx_VMath, Lx_Tool, Lx_Vector, Lx_Image;

const
  LXa_RAYCASTPACKET          = 'RaycastPacket'    ;
  LXa_PAINTBRUSHPACKET       = 'PaintBrushPacket' ;
  LXa_PAINTINKPACKET         = 'PaintInkPacket'   ;
  LXa_PAINTNOZZLEPACKET      = 'PaintNozzlePacket';

  LXfPAINTBRUSH_2D           = $01;
  LXfPAINTBRUSH_3D           = $02;
  LXfPAINTBRUSH_3D_RGBA      = $04;

  LXfPAINTSTEP_BUMP          = $01;
  LXfPAINT_ROLLER            = $02;
  LXfPAINT_STAMP             = $04;

  LXf_PAINT_INK_PERPIXEL     = $01;
  LXf_PAINT_INK_3D           = $02;
  LXf_PAINT_INK_STAMP        = $04;

  LXi_VIEWTYPE_3D            = 0;
  LXi_VIEWTYPE_UV            = 1;

  LXiTIE_TYPE_NONE           = 0;
  LXiTIE_TYPE_DOWN           = 1;
  LXiTIE_TYPE_MOVE           = 2;
  LXiTIE_TYPE_UP             = 3;

  LXiTIE_INPUT_I0            = 0;
  LXiTIE_INPUT_I1            = 1;

  LXiTIE_CURVE_EDIT          = 2 ;
  LXiTIE_CURVE_ADD           = 3 ;
  LXiTIE_CURVE_DELETE        = 4 ;
  LXiTIE_CURVE_DELETE_ALL    = 5 ;
  LXiTIE_CURVE_MOVE          = 6 ;
  LXiTIE_CURVE_MOVE_ALL      = 7 ;
  LXiTIE_CURVE_MOVE_CONS     = 8 ;
  LXiTIE_CURVE_MOVE_CONS_ALL = 9 ;
  LXiTIE_CURVE_SCALE         = 10;
  LXiTIE_CURVE_SCALE_ALL     = 11;
  LXiTIE_CURVE_ALT           = 12;

  LXiTIE_GENERAL_PRI         = 20;
  LXiTIE_GENERAL_SEC         = 21;
  LXiTIE_GENERAL_TER         = 22;
  LXiTIE_GENERAL_PRI_ALT     = 23;
  LXiTIE_GENERAL_SEC_ALT     = 24;
  LXiTIE_GENERAL_TER_ALT     = 25;
  LXiTIE_GENERAL_PRI_CONS    = 26;
  LXiTIE_GENERAL_SEC_CONS    = 27;
  LXiTIE_GENERAL_TER_CONS    = 28;
  LXiTIE_GENERAL_CLICK_1     = 29;
  LXiTIE_GENERAL_CLICK_2     = 30;

  LXiPAINTMODE_SET           = 0;
  LXiPAINTMODE_ADD           = 1;
  LXiPAINTMODE_MAX           = 2;

  LXsP_TOOL_VIEW_EVENT       = 'ToolViewEvent'  ;
  LXsP_TOOL_3D_EVENT         = 'Tool3DEvent'    ;
  LXsP_TOOL_SCREEN_EVENT     = 'ToolScreenEvent';
  LXsP_TOOL_INPUT_EVENT      = 'ToolInputEvent' ;
  LXsP_TOOL_TABLET_EVENT     = 'ToolTabletEvent';
  LXsP_TOOL_COLOR            = 'ToolColor'      ;
  LXsP_TOOL_RAYCAST          = 'ToolRaycast'    ;
  LXsP_TOOL_HIT_EVENT        = 'ToolHitEvent'   ;
  LXsP_TOOL_STROKE_EVENT     = 'ToolStrokeEvent';
  LXsP_TOOL_PAINT_TARGET     = 'ToolPaintTarget';
  LXsP_TOOL_PAINT_STROKE     = 'ToolPaintStroke';
  LXsP_TOOL_PAINT_BRUSH      = 'ToolPaintBrush' ;
  LXsP_TOOL_PAINT_INK        = 'ToolPaintInk'   ;
  LXsP_TOOL_PAINT_NOZZLE     = 'ToolPaintNozzle';
  LXsP_TOOL_PROFILE          = 'toolProfile'    ;
  LXsP_TOOL_IMAGE            = 'toolImage'      ;
  LXsP_TOOL_SNAPELEMENT      = 'toolSnapElement';

  LXu_RAYCASTPACKET          = '{D622B573-2638-4A47-AD91-6BC7A6D2D30B}';
  LXu_PAINTBRUSHPACKET       = '{9283C21E-77FC-402D-B22A-7B26285888C4}';
  LXu_PAINTINKPACKET         = '{340EE412-232D-4619-974D-7E59C7B39353}';
  LXu_PAINTNOZZLEPACKET      = '{F0BB49ED-0BBB-448a-8339-F69F78E95048}';

type
  ILxStrokePacket = ILxVectorList;

  PViewport = ^Viewport;
  Viewport  = record end;

  PAGLView  = ^AGLView;
  AGLView   = record end;

  PLXpToolViewEvent = ^LXpToolViewEvent;
  LXpToolViewEvent  = record
    VPort : PViewport;
    View  : PAGLView ;
    Flags : UInt32   ;
    Type_ : UInt32   ;
  end;

  PLXpTool3DEvent = ^LXpTool3DEvent;
  LXpTool3DEvent  = record
    V0 , DV  : LXtVector;
    RV0, RDV : LXtVector;
  end;

  PLXpToolScreenEvent = ^LXpToolScreenEvent;
  LXpToolScreenEvent  = record
    PX , PY  : Integer;
    CX , CY  : Integer;
    FPX, FPY : Single ;
    FCX, FCY : Single ;
  end;

  PLXpToolInputEvent = ^LXpToolInputEvent;
  LXpToolInputEvent  = record
    Mode  : Integer;
    Input : Integer;
    Count : Integer;
    Part  : Integer;
    &Type : Integer;
    Haul  : Integer;
  end;

  PLXpToolTabletEvent = ^LXpToolTabletEvent;
  LXpToolTabletEvent  = record
    Exists  : Integer               ;
    InUse   : Integer               ;

    Normal  : Double                ;
    Tangent : Double                ;
    Tilt    : array [0..1] of Double;
    Twist   : Double                ;
  end;

  PLXpToolColor = ^LXpToolColor;
  LXpToolColor  = record
    FG : array [0..3] of Single;
    BG : array [0..3] of Single;
  end;

  PLXtHitPolygon = ^LXtHitPolygon;
  LXtHitPolygon  = record
    Pol    : PLXtPol               ;
    Pos    : LXtVector             ;
    Nrm    : LXtVector             ;
    UV     : array [0..1] of Single;
    Cosine : Single                ;
    Disp   : Single                ;
    Surf   : Pointer               ;
    MBin   : Pointer               ;
  end;

  PLXtHitEdge = ^LXtHitEdge;
  LXtHitEdge  = record
    Edge : PLXtOldEdge;
    Pos  : LXtVector  ;
    T    : Single     ;
  end;

  PLXtHitVertex = ^LXtHitVertex;
  LXtHitVertex  = record
    Vrt : PLXtPnt  ;
    Pos : LXtVector;
  end;

  PLXpToolHitEvent = ^LXpToolHitEvent;
  LXpToolHitEvent  = record
    Hit  : LXtHitPolygon;
    Dist : Single       ;
  end;

  PLXtHitItem = ^LXtHitItem;
  LXtHitItem  = record
    Item   : IUnknown ;
    Pos    : LXtVector;
    Nrm    : LXtVector;
    IsMesh : Integer  ;
  end;

  PLXpToolPaintTarget = ^LXpToolPaintTarget;
  LXpToolPaintTarget  = record
    Image      : ILxImage;
    ProjMode   ,
    ProjWidth  ,
    ProjHeight : Integer ;
    XC, YC     : Integer ;
    XP, YP     : Integer ;
    FXP, FYP   : Single  ;
  end;

  PLXpToolPaintStroke = ^LXpToolPaintStroke;
  LXpToolPaintStroke  = record
    Start   ,
    &End    : array [0..1] of Single;
    Length  : Single                ;
    Total   : Single                ;
    Current : Single                ;
    Align   : Integer               ;
  end;

  PLXtPaintBrush = ^LXtPaintBrush;
  LXtPaintBrush  = record
    Width,
    Height   : Integer;
    Wgt      : PSingle;
    RGB      : PSingle;
    Rotation : Single ;
    Mode     : Integer;
    Flags    : Integer;
  end;

  PLXpToolProfile = ^LXpToolProfile;
  LXpToolProfile  = record
    XObj      : IUnknown;
    Dimension : Integer ;
  end;

  PLXpToolImage = ^LXpToolImage;
  LXpToolImage  = record
    Path  : PChar   ;
    Flags : Integer ;
  end;

  PLXpToolSnapElement = ^LXpToolSnapElement;
  LXpToolSnapElement  = record
    Mesh       : PLXtMesh ;
    VMap       : PLXtVMap ;
    &Type      : LXtID4   ;
    Pol        : PLXtPol  ;
    Vrt0, Vrt1 : PLXtPnt  ;
    Pos        : LXtVector;
    CX, CY     : Double   ;
    Dist       : Double   ;
    View       : PAGLView ;
  end;

  ILxRaycastPacket = interface
  [LXu_RAYCASTPACKET]
    function HitPolygon(ToolVector : IUnknown      ;
                        X          : Single        ;
                        Y          : Single        ;
                        Hit        : PLXtHitPolygon) : Integer;
    function HitEdge   (ToolVector : IUnknown      ;
                        X          : Single        ;
                        Y          : Single        ;
                        Hit        : PLXtHitEdge   ) : Integer;
    function HitVertex (ToolVector : IUnknown      ;
                        X          : Single        ;
                        Y          : Single        ;
                        Hit        : PLXtHitVertex ) : Integer;
    function HitItem   (ToolVector : IUnknown      ;
                        X          : Single        ;
                        Y          : Single        ;
                        Hit        : PLXtHitItem   ) : Integer;
  end;

  ILxPaintBrushPacket = interface
  [LXu_PAINTBRUSHPACKET]
    function Flags                                     : Integer;
    function Size                                      : Single ;
    function BBox  (      ToolVector : IUnknown      ;
                    const Center     : LXtVector     ;
                          Size_      : Double        ;
                          BBox       : PLXtBBox      ) : Integer;
    function Eval2D(      ToolVector : IUnknown      ;
                          Multiplier : Single        ;
                          Brush      : PLXtPaintBrush) : Integer;
    function Eval3D(      ToolVector : IUnknown      ;
                    const Center     : LXtVector     ;
                    const WPos       : LXtVector     ;
                    const BPos       : LXtVector     ;
                          Rad        : Double        ;
                          RGBA       : PSingle       ) : Double ;
  end;

  ILxPaintInkPacket = interface
  [LXu_PAINTINKPACKET]
    function Flags(ToolVector : IUnknown      ) : Integer ;
    function Color(ToolVector : IUnknown      ;
                   Flags_     : Integer       ;
                   RGBA       : LXtColorRGBA  ) : Integer ;
    function Stamp(Brush      : PLXtPaintBrush) : Integer ;
  end;

  ILxPaintNozzlePacket = interface
  [LXu_PAINTNOZZLEPACKET]
    function Paint (ToolVector : IUnknown;
                    BrushSize  : Single  ) : Integer;
    function Jitter(ToolVector : IUnknown;
                    BrushSize  : Single  ;
                    XJ         : PInteger;
                    YJ         : PInteger) : Integer;
    function Nozzle(ToolVector : IUnknown;
                    Strength   : PSingle ;
                    Size       : PSingle ;
                    Rotation   : PSingle ) : Integer;
  end;

implementation

end.

